home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ptv1n2.arc / MOUSE.C < prev    next >
C/C++ Source or Header  |  1990-06-14  |  2KB  |  68 lines

  1. /* mouse.c -- Routines to support a Microsoft compatible mouse.
  2.  * This package assumes that you are running under graphics mode.
  3.  */
  4. #include <dos.h>
  5. #include <graphics.h>
  6. #include <stdio.h>
  7. #include "mouse.h"
  8.  
  9. /* Communicates with the mouse driver */
  10. void mouse(int *m1, int *m2, int *m3, int *m4)
  11. {
  12.   union REGS inregs, outregs;
  13.  
  14.   inregs.x.ax = *m1;   inregs.x.bx = *m2;
  15.   inregs.x.cx = *m3;   inregs.x.dx = *m4;
  16.   int86(0x33,&inregs,&outregs);
  17.   *m1 = outregs.x.ax;  *m2 = outregs.x.bx;
  18.   *m3 = outregs.x.cx;  *m4 = outregs.x.dx;
  19. }
  20.  
  21. /* Initialize the mouse */
  22. int initmouse(void)
  23. {
  24.   int gmode, m1, m2, m3, m4;
  25.   char far *memory = (char far *)0x004000049L;
  26.  
  27.   m1 = RESET_MOUSE;    mouse(&m1,&m2,&m3,&m4);
  28.   if (m1) {
  29.     /* Hercules card requires an extra step */
  30.     gmode = getgraphmode();
  31.     if (gmode == HERCMONOHI) {
  32.       *memory = 0x06;
  33.       m1 = RESET_MOUSE;  mouse(&m1,&m2,&m3,&m4);
  34.     }
  35.     mousestatus(SHOW_MOUSE);
  36.     return(1);
  37.   }
  38.   else /* Mouse not found, return failure flag */
  39.     return(0);
  40. }
  41.  
  42. /* Hide or show the mouse */
  43. void mousestatus(int stateofmouse)
  44. {
  45.   int m2, m3, m4;
  46.  
  47.   mouse(&stateofmouse,&m2,&m3,&m4);
  48. }
  49.  
  50. /*  Get the current location of the mouse cursor */
  51. void getmousecoords(int *x, int *y)
  52. {
  53.   int m1, m2;
  54.  
  55.   m1 = GET_MOUSE_STATUS;   mouse(&m1,&m2,x,y);
  56.   /* Adjust for virtual coordinates of the mouse */
  57.   if (getmaxx() == 319) (*x) /= 2;
  58. }
  59.  
  60. /* Returns 1 if the mouse button condition specified occurred */
  61. int buttonstatus(int condition, int whichbutton)
  62. {
  63.   int m3, m4;
  64.  
  65.   mouse(&condition,&whichbutton,&m3,&m4);
  66.   if (whichbutton) return(1); else  return(0);
  67. }
  68.